Page({

  data: {
    windowHeight: 100,
    // 默认地址的下标index
    selectedIndex: 0,
    addressArr: [
      {
        name: 'LEO',
        tel: '18100004523',
        address: '上海市 浦东新区 鹤永路740弄 汇成家园'
      },
      {
        name: 'LEO',
        tel: '18100004523',
        address: '上海市 浦东新区 鹤永路740弄 汇成家园'
      },
      {
        name: 'LEO',
        tel: '18100004523',
        address: '上海市 浦东新区 鹤永路740弄 汇成家园'
      },
    ]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var login = wx.getStorageSync('login')
    
    //设置scroll-view高度
    wx.getSystemInfo({
      success: function (res) {
        that.setData({ windowHeight: res.windowHeight });
      }
    });
  },
  // 设置默认地址
  addressFirst(e) {
    this.setData({ selectedIndex: parseInt(e.currentTarget.dataset.addressindex) });
  },
  // 新增地址
  addAddress() {
    wx.navigateTo({ url: '../addAddress/addAddress' });
  },
  // 删除
  delete(e) {
    let addressArrCopy = this.data.addressArr;
    let index = e.currentTarget.dataset.addressindex;
    addressArrCopy.splice(index,1);
    this.setData({addressArr:addressArrCopy});
  },
  // 编辑
  edit() {
    wx.navigateTo({ url: '../addAddress/addAddress' });
  },
})
